1. Field of the Invention
The invention relates to an image processing device and a storage medium storing an image processing program, and more specifically to an image processing device and a storage medium storing an image processing program that performs a Retinex process on an image.
2. Description of the Related Art
When taking a photograph of a subject under backlit conditions, e,g. against the sun, the image of the subject portion is an indistinct backlit image with low lightness and contrast, making it difficult to make out details of the subject. Image processing is performed to improve the quality of these backlit images, as well as images suffering in quality due to overexposure, underexposure, blurring due to jiggling when capturing the image, noise, insufficient light, and the like, in order to improve lightness and contrast in the image. One method used in conventional image processing is a Retinex process.
The Retinex process preserves the input image data for high-quality regions and improves the image quality primarily in low-quality regions. The Retinex process uses Gaussian filters for calibrating pixel data in the original image to values reflecting data of surrounding pixels, calculates reference component data for the original image from the natural logarithm of the calibrated pixel data, and calculates luminance component data by dividing pixel data of the original image by pixel components of the original image. Specifically, this process divides the original image into reference components and luminance components. Next, a process is performed to calibrate the brightness and level (contrast) of the luminance component through gamma correction or the like and subsequently generates improved image data for the original image in backlit portions and the like by combining the calibrated luminance components with the reference components. The reference component is found by normalizing a reflectance R(x, y))
Next, normalization of the reflectance R(x, y) will be described with reference to FIG. 1. The reflectance R(x, y) is calculated according to equation 1 shown below.
                                          R            ⁡                          (                              x                ,                y                            )                                =          log                ⁣                              Y            ⁡                          (                              x                ,                y                            )                                                          F              ⁡                              (                                  x                  ,                  y                                )                                      *                          Y              ⁡                              (                                  x                  ,                  y                                )                                                                        [                  Equation          ⁢                                          ⁢          1                ]            In equation 1, x is the horizontal coordinate, y is the vertical coordinate, Y(x, y) is the luminance value of the pixel at the coordinate (x, y), and “*” is the convolution operator. Further, log is the natural logarithm to the base e. F(x, y) represents a Gaussian filter factor at the subject pixel (x, y) as shown in the following equation:F(x, y)=exp(−(x2+y2)/(c/75)2)   [Equation 2]where c is a coefficient determined dependently on the number of the peripheral pixels. So, the value F(x, y)* Y(x, y) indicates the average value of the luminance values of the peripheral pixels.
The reflectance R(x, y) found in the equation 1 for all coordinates are normalized to form a histogram. Normalization is achieved by setting the minimum reflectance R (x, y) among all coordinates to 0 and the maximum value to 255 and linearly setting all reflectance R(x, y) values for other coordinates to integers between 0 and 255. The histogram is formed by tabulating the frequency of pixels indicating each computed value between the maximum and minimum values, An example of the histogram is shown in FIG. 1.
From this histogram, a median value M is found. A clipped range of reflectance R(x, y) values (normalizing parameters) is set based on the median value M and the histogram. As an example, the clipped range has an upper limit U including 45% of all samplincgs greater than the median value M, and a lower limit D including 45% of all samplings smaller than the median value M. The reflectance R(x, y) values corresponding to the upper limit U and lower limit D are called the UpR and DownR values, respectively. In this way, the clipped range (UpR, DownR) is obtained.
A normalized reflectance (normalized Retinex value) refle (x, y) is set to 0.0 when the value of reflectance R(x, y) is less than or equal to the DownR, is set to 1.0 when the value of reflectance R(x, y) is greater than or equal to UpR, and is calculated based on the following equation 3 when the value of reflectance R(x, y) is greater than DownR and less than UpR.
                              refle          ⁡                      (                          x              ,              y                        )                          =                                            R              ⁡                              (                                  x                  ,                  y                                )                                      -                          Down              ⁢                                                          ⁢              R                                                          Up              ⁢                                                          ⁢              R                        -                          Down              ⁢                                                          ⁢              R                                                          [                  Equation          ⁢                                          ⁢          3                ]            Through this process, refle(x, y) is normalized to a value between 0.0 and 1.0. Through experimentation, it has been found preferable to add 0.3 to this value to obtain a value between 0.3 and 1.3 for refle (x, y).
U S. Pat. No. 6,885,482 (corresponding to Japanese Patent Application Publication No. 2001-69525) discloses a method of converting RGB values to a color space configured of a luminance component and chromatic components, such as YCbCr or YIQ, performing the Retinex process only on the luminance component Y, while maintaining the chromatic components, and converting the values back to RGB. Calibrating only the luminance component (i.e. not calibrating the chromatic components) prevents an upset in the color balance and a shift in color. Further, since the Retinex process is performed only on the luminance component, this method requires fewer calculations than a method for performing the Retinex process on each RGB plane and, hence, can complete the process quicker, Further, less storage space is required for normalizing reflectance R(x, y) values since only the luminance value is stored, rather than each RGB value.
U.S. Patent Application Publication No. 2004/0091164 (corresponding to Japanese Patent No. 3,731,577) discloses a method for improving the processing speed in the Retinex process. This method forms a reduced image (low-resolution image) from the original image using the average pixel method or the like, forms a peripheral average luminance image (blurred image) by finding the surrounding average luminance for each pixel in the reduced image, forms a Retinex processed image from the original image and an image produced by expanding the blurred image, and forms an output image from the original image and the Retinex processed image.